﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;

namespace Wix.Aura.Common.CustomTypes {
	public class LocalizableInteger {

		public LocalizableInteger(int value) {
			Value = value;
		}

		public LocalizableInteger(string variableName) {
			Verify(variableName);
			VariableName = variableName;
		}

		private static void Verify(string variableName) {
			if (!Regex.IsMatch(variableName, @"[_A-Za-z][0-9A-Za-z_]*"))
				throw new ArgumentException("Parameter variableName must match '[_A-Za-z][0-9A-Za-z_]*' RegularExpression", "variableName");
		}

		public int? Value { get; private set; }
		public string VariableName { get; private set; }

		public override string ToString() {
			if (Value.HasValue)
				return Value.ToString();
			return string.Format(CultureInfo.InvariantCulture, "$(loc.{0})", VariableName);
		}
	}
}
